home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / programming / other / cyberxxxsrc / decoder / txt / decoderaw.c < prev    next >
C/C++ Source or Header  |  1999-02-08  |  6KB  |  270 lines

  1. /*
  2. sc:c/sc opt txt/DecodeRAW.c
  3. */
  4.  
  5. #include "Decode.h"
  6. #include "YUV.h"
  7.  
  8. struct RAWData {
  9.   uchar gray;
  10.   uchar *rngLimit;
  11.   struct RGBTriple *cmap;
  12. };
  13.  
  14. /* /// "DecodeRAW1()" */
  15. __asm void DecodeRAW1(REG(a0) uchar *from,
  16.                       REG(a1) uchar *to,
  17.                       REG(d0) ulong width,
  18.                       REG(d1) ulong height,
  19.                       REG(d2) ulong encSize,
  20.                       REG(a2) uchar *spec)
  21. {
  22.   ulong black=0x00;
  23.   ulong white=0x01;
  24.   ulong i=(width*height)>>1;
  25.  
  26.   while (i--) {
  27.     ulong d=*from++;
  28.     to[0]=(d & 0x80) ? white : black;
  29.     to[1]=(d & 0x40) ? white : black;
  30.     to[2]=(d & 0x20) ? white : black;
  31.     to[3]=(d & 0x10) ? white : black;
  32.     to[4]=(d & 0x08) ? white : black;
  33.     to[5]=(d & 0x04) ? white : black;
  34.     to[6]=(d & 0x02) ? white : black;
  35.     to[7]=(d & 0x01) ? white : black;
  36.     to+=8;
  37.   }
  38. }
  39. /* \\\ */
  40.  
  41. /* /// "DecodeRAW4()" */
  42. __asm void DecodeRAW4(REG(a0) uchar *from,
  43.                       REG(a1) uchar *to,
  44.                       REG(d0) ulong width,
  45.                       REG(d1) ulong height,
  46.                       REG(d2) ulong encSize,
  47.                       REG(a2) uchar *spec)
  48. {
  49.   ulong i=(width*height)>>1;
  50.  
  51.   while (i--) {
  52.     ulong d=*from++;
  53.     to[0]=(d>>4);
  54.     to[1]=d & 0x0f;
  55.     to+=2;
  56.   }
  57. }
  58. /* \\\ */
  59.  
  60. /* /// "DecodeRAW16toRGB()" */
  61. __asm void DecodeRAW16toRGB(REG(a0) ushort *from,
  62.                             REG(a1) uchar *to,
  63.                             REG(d0) ulong width,
  64.                             REG(d1) ulong height,
  65.                             REG(d2) ulong encSize,
  66.                             REG(a2) uchar *spec)
  67. {
  68.   ulong i=width*height;
  69.  
  70.   while (i--) {
  71.     ulong d, r, g, b;
  72.     d=*from++;
  73.     ColorToRGB(d,r,g,b);
  74.     to[0]=r;
  75.     to[1]=g;
  76.     to[2]=b;
  77.     to+=3;
  78.   }
  79. }
  80. /* \\\ */
  81.  
  82. /* /// "DecodeRAW16to332()" */
  83. __asm void DecodeRAW16to332(REG(a0) ushort *from,
  84.                             REG(a1) uchar *to,
  85.                             REG(d0) ulong width,
  86.                             REG(d1) ulong height,
  87.                             REG(d2) ulong encSize,
  88.                             REG(a2) struct RAWData *spec)
  89. {
  90.   ulong i=width*height;
  91.  
  92.   if (spec->gray) {
  93.     while (i--) {
  94.       ulong d;
  95.       d=*from++;
  96.       ColorTo332Gray(d,*to++);
  97.     }
  98.   } else {
  99.     while (i--) {
  100.       ulong d;
  101.       d=*from++;
  102.       ColorTo332(d,*to++);
  103.     }
  104.   }
  105. }
  106. /* \\\ */
  107.  
  108. /* /// "DecodeRAW16to332Dith()" */
  109. __asm void DecodeRAW16to332Dith(REG(a0) ushort *from,
  110.                                 REG(a1) uchar *to,
  111.                                 REG(d0) ulong width,
  112.                                 REG(d1) ulong height,
  113.                                 REG(d2) ulong encSize,
  114.                                 REG(a2) struct RAWData *spec)
  115. {
  116.   uchar *rngLimit=spec->rngLimit;
  117.   struct RGBTriple *cmap=spec->cmap;
  118.  
  119.   while (height--) {
  120.     uchar r, g, b;
  121.     long re=0, ge=0, be=0, w=width;
  122.     while (w--) {
  123.       ulong d, color;
  124.       d=*from++;
  125.       ColorToRGB(d,r,g,b);
  126.       DitherGetRGB(r,g,b,re,ge,be,color);
  127.       *to++=color;
  128.     }
  129.   }
  130. }
  131. /* \\\ */
  132.  
  133. /* /// "DecodeRAW24to332()" */
  134. __asm void DecodeRAW24to332(REG(a0) uchar *from,
  135.                             REG(a1) uchar *to,
  136.                             REG(d0) ulong width,
  137.                             REG(d1) ulong height,
  138.                             REG(d2) ulong encSize,
  139.                             REG(a2) struct RAWData *spec)
  140. {
  141.   ulong i=width*height;
  142.  
  143.   if (spec->gray) {
  144.     while (i--) {
  145.       uchar r, g, b;
  146.       r=from[0];
  147.       g=from[1];
  148.       b=from[2];
  149.       from+=3;
  150.       *to++=RGB8toGray(r,g,b);
  151.     }
  152.   } else {
  153.     while (i--) {
  154.       uchar r, g, b;
  155.       r=from[0];
  156.       g=from[1];
  157.       b=from[2];
  158.       from+=3;
  159.       *to++=RGBto332(r,g,b,scale8);
  160.     }
  161.   }
  162. }
  163. /* \\\ */
  164.  
  165. /* /// "DecodeRAW24to332Dith()" */
  166. __asm void DecodeRAW24to332Dith(REG(a0) uchar *from,
  167.                                 REG(a1) uchar *to,
  168.                                 REG(d0) ulong width,
  169.                                 REG(d1) ulong height,
  170.                                 REG(d2) ulong encSize,
  171.                                 REG(a2) struct RAWData *spec)
  172. {
  173.   uchar *rngLimit=spec->rngLimit;
  174.   struct RGBTriple *cmap=spec->cmap;
  175.  
  176.   while (height--) {
  177.     uchar r, g, b;
  178.     long re=0, ge=0, be=0, w=width;
  179.     while (w--) {
  180.       ulong color;
  181.       r=*from++;
  182.       g=*from++;
  183.       b=*from++;
  184.       DitherGetRGB(r,g,b,re,ge,be,color);
  185.       *to++=color;
  186.     }
  187.   }
  188. }
  189. /* \\\ */
  190.  
  191. /* /// "DecodeRAW32toRGB()" */
  192. __asm void DecodeRAW32toRGB(REG(a0) uchar *from,
  193.                             REG(a1) uchar *to,
  194.                             REG(d0) ulong width,
  195.                             REG(d1) ulong height,
  196.                             REG(d2) ulong encSize,
  197.                             REG(a2) uchar *spec)
  198. {
  199.   ulong i=width*height;
  200.  
  201.   while (i--) {
  202.     to[0]=from[1]; /* r */
  203.     to[1]=from[2]; /* g */
  204.     to[2]=from[3]; /* b */
  205.     to+=3;
  206.     from+=4;
  207.   }
  208. }
  209. /* \\\ */
  210.  
  211. /* /// "DecodeRAW32to332()" */
  212. __asm void DecodeRAW32to332(REG(a0) uchar *from,
  213.                             REG(a1) uchar *to,
  214.                             REG(d0) ulong width,
  215.                             REG(d1) ulong height,
  216.                             REG(d2) ulong encSize,
  217.                             REG(a2) struct RAWData *spec)
  218. {
  219.   ulong i=width*height;
  220.  
  221.   if (spec->gray) {
  222.     while (i--) {
  223.       uchar r, g, b;
  224.       r=from[1];
  225.       g=from[2];
  226.       b=from[3];
  227.       from+=4;
  228.       *to++=RGB8toGray(r,g,b);
  229.     }
  230.   } else {
  231.     while (i--) {
  232.       uchar r, g, b;
  233.       r=from[1];
  234.       g=from[2];
  235.       b=from[3];
  236.       from+=4;
  237.       *to++=RGBto332(r,g,b,scale8);
  238.     }
  239.   }
  240. }
  241. /* \\\ */
  242.  
  243. /* /// "DecodeRAW32to332Dith()" */
  244. __asm void DecodeRAW32to332Dith(REG(a0) uchar *from,
  245.                                 REG(a1) uchar *to,
  246.                                 REG(d0) ulong width,
  247.                                 REG(d1) ulong height,
  248.                                 REG(d2) ulong encSize,
  249.                                 REG(a2) struct RAWData *spec)
  250. {
  251.   uchar *rngLimit=spec->rngLimit;
  252.   struct RGBTriple *cmap=spec->cmap;
  253.  
  254.   while (height--) {
  255.     uchar r, g, b;
  256.     long re=0, ge=0, be=0, w=width;
  257.     while (w--) {
  258.       ulong color;
  259.       r=from[1];
  260.       g=from[2];
  261.       b=from[3];
  262.       from+=4;
  263.       DitherGetRGB(r,g,b,re,ge,be,color);
  264.       *to++=color;
  265.     }
  266.   }
  267. }
  268. /* \\\ */
  269.  
  270.